package com.ning.activitys.skysound.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;

import com.ning.activitys.skysound.R;
import com.ning.activitys.skysound.base.BaseFragment;
import com.ning.activitys.skysound.fragment.mymusic.AllMusicFragment;
import com.ning.activitys.skysound.fragment.mymusic.LikeMusicFragment;
import com.ning.activitys.skysound.fragment.mymusic.RecentMusicFragment;

/**
 * Created by dllo on 16/1/16.
 */
public class MyMusicFrament extends BaseFragment{

    private TabHost tabHost;
    private FragmentManager fragmentManager;
    private volatile static MyMusicFrament myMusicFrament;//单例的引用

    public static MyMusicFrament getInstance() {
        if (myMusicFrament == null) {
            //线程锁,只有一个线程可以调用
            synchronized (AllMusicFragment.class) {
                if (myMusicFrament == null) {
                    myMusicFrament = new MyMusicFrament();
                }
            }
        }
        return myMusicFrament;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_my_music,null);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
        tabHost.setup();

        tabHost.addTab(tabHost.newTabSpec("1").setIndicator("全部").setContent(R.id.th_tab_all_music_my_music));
        tabHost.addTab(tabHost.newTabSpec("2").setIndicator("喜欢").setContent(R.id.th_tab_like_music_my_music));
        tabHost.addTab(tabHost.newTabSpec("3").setIndicator("最近").setContent(R.id.th_tab_recent_music_my_music));

        fragmentManager = getActivity().getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.th_tab_all_music_my_music,new AllMusicFragment());
        fragmentTransaction.replace(R.id.th_tab_like_music_my_music,new LikeMusicFragment());
        fragmentTransaction.replace(R.id.th_tab_recent_music_my_music,new RecentMusicFragment());

        fragmentTransaction.commit();
    }



}
